﻿using System;
using BLL.Validation;

namespace BLL.Entities
{
  public abstract class BaseBusinessEntity
  {
    protected readonly ValidationResult _validator = new ValidationResult();
    public Guid EntityID { get; set; }
    public bool IsNew { get; set; }
    public DateTime Created { get; set; }
    public DateTime Updated { get; set; }
    public bool IsDeleted { get; set; }


    public static T CreateNewInstance<T>() where T : BaseBusinessEntity, new()
    {
      var obj = new T
                  {
                    EntityID = Guid.NewGuid(),
                    Created = DateTime.UtcNow,
                    IsNew = true
                  };
      return obj;
    }


    public virtual ValidationResult Validate()
    {
      if (EntityID == Guid.Empty) _validator.Add(ValidationErrors.InvalidEntityID);
      return _validator;
    }
  }
}